package com.ymatou.auth.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.BillsLoginIdModifyEventRequestDtoBean;
import com.ymatou.auth.service.BillsLoginIdModifyEventRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.mongo.LoginIdUpdateEventHistoryMongoWapper;
import com.ymttest.utils.TestDataManager;
/**
*用户在指定时间内登陆失败的次数接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BillsLoginIdModifyEventRequestDto{
	private static BillsLoginIdModifyEventRequestDtoBean billsloginidmodifyeventrequestdtoBean;
	private static BillsLoginIdModifyEventRequestDtoCall billsloginidmodifyeventrequestdtoCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户在指定时间内登陆失败的次数接口");
	}

	@Before
	public void caseUp() {
		billsloginidmodifyeventrequestdtoBean=new BillsLoginIdModifyEventRequestDtoBean();
		billsloginidmodifyeventrequestdtoCall=new BillsLoginIdModifyEventRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(billsloginidmodifyeventrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_001() {
		Logger.start(true,"正确返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			String ip=TestDataManager.getRandomIp();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			int userId=(Integer)UserMap.get("userId");
			String login1=UserMap.get("loginId").toString();
			String login2="ReName_"+TestDataManager.getRandomNum(9);
			UserCallService.modifyLoginId(userId, login2);
			Thread.sleep(2000);
			billsloginidmodifyeventrequestdtoBean.setUserId(userId);
			billsloginidmodifyeventrequestdtoBean.setLoginId(login2);
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(1, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_002() {
		Logger.start(true,"不输入LoginId，返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			String ip=TestDataManager.getRandomIp();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			int userId=(Integer)UserMap.get("userId");
			String login1=UserMap.get("loginId").toString();
			String login2="ReName_"+TestDataManager.getRandomNum(9);
			UserCallService.modifyLoginId(userId, login2);
			billsloginidmodifyeventrequestdtoBean.setUserId(userId);
//			billsloginidmodifyeventrequestdtoBean.setLoginId(login2);
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(1, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_003() {
		Logger.start(true,"不输入UserId，返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			String ip=TestDataManager.getRandomIp();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			int userId=(Integer)UserMap.get("userId");
			String login1=UserMap.get("loginId").toString();
			String login2="ReName_"+TestDataManager.getRandomNum(9);
			UserCallService.modifyLoginId(userId, login2);
//			billsloginidmodifyeventrequestdtoBean.setUserId(userId);
			billsloginidmodifyeventrequestdtoBean.setLoginId(login2);
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(1, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_004() {
		Logger.start(false,"不输入ActionSource, 返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			String ip=TestDataManager.getRandomIp();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			int userId=(Integer)UserMap.get("userId");
			String login1=UserMap.get("loginId").toString();
			String login2="ReName_"+TestDataManager.getRandomNum(9);
			UserCallService.modifyLoginId(userId, login2);
			billsloginidmodifyeventrequestdtoBean.setUserId(userId);
			billsloginidmodifyeventrequestdtoBean.setLoginId(login2);
//			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(1, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_005() {
		Logger.start(true,"输入不存在的UserId和正确的LoginId, 返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			billsloginidmodifyeventrequestdtoBean.setUserId(123666666);
			billsloginidmodifyeventrequestdtoBean.setLoginId("dmmemo");
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(0, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_006() {
		Logger.start(false,"输入不存在的LoginId和正确的UserId, 返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			//不匹配
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			String ip=TestDataManager.getRandomIp();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			int userId=(Integer)UserMap.get("userId");
			String login1=UserMap.get("loginId").toString();
			String login2="ReName_"+TestDataManager.getRandomNum(9);
			UserCallService.modifyLoginId(userId, login2);
			billsloginidmodifyeventrequestdtoBean.setUserId(userId);
			billsloginidmodifyeventrequestdtoBean.setLoginId(login2+1);
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(0, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BillsLoginIdModifyEventRequestDto_007() {
		Logger.start(false, "输入错误的LoginId和错误的UserId, 返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			billsloginidmodifyeventrequestdtoBean.setUserId(123666666);
			billsloginidmodifyeventrequestdtoBean.setLoginId("test007");
			billsloginidmodifyeventrequestdtoBean.setActionSource("App");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(0, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore//需要确认需求，是否存在传入不存在的ActionSource的情况
	public void Tc_BillsLoginIdModifyEventRequestDto_008() {
		Logger.start(false,"输入不存在的ActionSource, 返回用户修改用户信息的次数, ActionSource为App说明用户来自手机App注册");
		try {
			billsloginidmodifyeventrequestdtoBean.setUserId(686967);
			billsloginidmodifyeventrequestdtoBean.setLoginId("dmmemo");
			billsloginidmodifyeventrequestdtoBean.setActionSource("aaa");
			billsloginidmodifyeventrequestdtoCall.setData(billsloginidmodifyeventrequestdtoBean);
			billsloginidmodifyeventrequestdtoCall.callService();			
			Logger.verifyEquals(true, billsloginidmodifyeventrequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(0, billsloginidmodifyeventrequestdtoCall.getModifyLoginIdCount(), "验证用户修改信息的次数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}